<script lang="ts" setup>
import { GameItem } from '@/typings';
import { List } from '@element-plus/icons-vue';

const props = defineProps<{ data: GameItem }>();
const emits = defineEmits<{ (e: 'collect', i: string, v: boolean); (e: 'detail') }>();
</script>

<template>
  <el-card class="game-card-wrap">
    <el-image class="game-cover" :src="data.cover" fit="cover" lazy />
    <div class="game-name">
      {{ data.name }}
      <el-text tag="ins">No.{{ data.index }}</el-text>
    </div>
    <el-descriptions class="game-info" :column="3" direction="vertical">
      <el-descriptions-item label="类型">{{ data.type }}</el-descriptions-item>
      <el-descriptions-item label="版本">{{ data.version }}</el-descriptions-item>
      <el-descriptions-item label="更新">{{ data.updateTime }}</el-descriptions-item>
    </el-descriptions>
    <div class="tags-wrap">
      <el-tag v-for="tag of data.tags" :key="tag">{{ tag }}</el-tag>
    </div>
    <div class="game-actions">
      <div v-if="!data.collect" @click="emits('collect', data.index, true)">
        <a-icon name="star" />收藏
      </div>
      <div v-else class="active" @click="emits('collect', data.index, false)">
        <a-icon name="star-fill" />已收藏
      </div>
      <div @click="emits('detail')">
        <el-icon><List /></el-icon>详情
      </div>
    </div>
  </el-card>
</template>

<style lang="scss" scoped>
.game-card-wrap {
  :deep(.el-card__body) {
    padding: 0;
  }
  & + & {
    margin-top: 20px;
  }
  .game-cover {
    width: 100%;
  }
  .game-name {
    padding: 10px;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .game-info {
    padding: 0 10px;
    :deep(.el-descriptions__table) {
      th,
      td {
        padding-bottom: 0 !important;
      }
    }
  }
  .tags-wrap {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 5px;
    .el-tag {
      margin: 5px;
      min-width: 68px;
    }
  }
  .game-actions {
    width: 100%;
    display: flex;
    align-items: center;
    border-top: 1px solid var(--el-border-color);
    color: var(--el-color-primary);
    & > div {
      width: 50%;
      padding: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-right: 1px solid var(--el-border-color);
      cursor: pointer;
      &:last-child {
        border-right: none;
      }
      &.active {
        color: var(--el-color-danger);
      }
    }
    .el-icon {
      font-size: 20px;
      margin-right: 4px;
    }
  }
}
</style>
